        TITL DAI FIRMWARE 2E000-2E1FC  V1.1
        ORG   :E000
*
*
*
*   ======================
*** SCREEN DRIVING PACKAGE ***
*   ======================
*
* Called by RST 5; DATA XX. XX indicates the
* offset of E000 for the different entrypoints.
*
***************
* ENTRYPOINTS *
***************
*
* Screen functions:
 REM
ZSINIT  JMP   SINIT     Initialise screen
ZSOUTC  JMP   SOUTC     Output one character
ZSCLT   JMP   SCOLT     Set text colours
ZSCUS   JMP   SCURS     Set cursor position
ZSCUA   JMP   SCURA     Ask cursor position and
 REM size character screen
ZSCUM   JMP   SCURM     Set cursor mode
ZSCUI   JMP   SCURI     Flash cursor
ZSFETC  JMP   SFETC     Get character from line
ZSMODE  JMP   SSETM     Change mode
ZSCLG   JMP   SCOLG     Set graphics colours
ZSDOT   JMP   SDOT      Draw a dot on the screen
ZSDRAW  JMP   SDRAW     Draw a line on the screen
ZSFILL  JMP   SFILL     Fill a rectangular area
ZSCRN   JMP   SSCRN     Ask colour of a point on the
 REM screen and the size of the
 REM graphics screen
* Edit functions:
 REM
ZEDIT   JMP   EINIT     Initialise editor
ZEDOB   JMP   EOBEY     Run edit command
*
*************************
* CONSTANT TABLE MODE 0 *
*************************
*
* These constant tables are moved into the screen
* variables in RAM (0084-0098) when the appropriate
* mode is entered.
*
* Except the last 4 data blocks, all values
* are offset from the screen top address (BFFF for
* a 48K machine). This is valid for all modes.
*
CON0    DBL   :0CB0     First free RAM byte
        DBL   :0000     Top of rolled area
        DBL   :0000     End graphics area
        DBL   :0010     Start character area
        DBL   :0CA0     End character area
        DBL   :0CB0     End screen
        DBL   :0000     End area used splitting mode
        DBL   :0000     Start archive save area
*
        DBL   :0000     Number of blobs horizontally
        DATA  :00       Number of lines of graphics
        DATA  :00       Number saved graphics lines
        DATA  :00       Number of bytes/line
*
****************************
* CONSTANT TABLE MODES 1/2 *
****************************
*
CON1    DBL   :0638     First free RAM byte
        DBL   :0130     Top area rolled up for mode
        DBL   :0628     End graphics area
        DBL   :0628     CHS (dummy)
        DBL   :0860     End character area
        DBL   :0638     End screen
        DBL   :0748     End area used splitting mode
        DBL   :0740     Start graphic archive area
*
        DBL   :0048     Number of blobs horizontally
        DATA  :41       Number of lines of graphics
        DATA  :0C       Number archive area lines
        DATA  :18       Number of bytes/line
*
******************************
* CONSTANT TABLE MODES 1A/2A *
******************************
*
CON1A   DBL   :0860     First free RAM byte
        DBL   :0130     Top of rolled area
        DBL   :0508     End graphics area
        DBL   :0518     Start character area
        DBL   :0730     End character area
        DBL   :0740     End screen
        DBL   :0748     End area used splitting mode
        DBL   :0628     Start graph temp save area
*
        DBL   :0048     Number of blobs horizontally
        DATA  :41       Number of lines of graphics
        DATA  :0C       Number saved graphics lines
        DATA  :18       Number of bytes/line
*
****************************
* CONSTANT TABLE MODES 3/4 *
****************************
*
CON3    DBL   :177C     First free RAM byte
        DBL   :0460     Top area rolled up
        DBL   :176C     End graphics area
        DBL   :176C     CHS (dummy)
        DBL   :19A4     End character area
        DBL   :177C     End screen
        DBL   :1BBC     End area used splitting mode
        DBL   :1554     Start graph archive area
*
        DBL   :00A0     Number of blobs horizontally
        DATA  :82       Number of lines of graphics
        DATA  :18       Number archive area lines
        DATA  :2E       Number of bytes/line
*
******************************
* CONSTANT TABLE MODES 3A/4A *
******************************
*
CON3A   DBL   :19A4     First free RAM byte
        DBL   :0460     Top of rolled area
        DBL   :131C     End graphics area
        DBL   :132C     Start character area
        DBL   :1544     End character area
        DBL   :1554     End screen
        DBL   :1BBC     End area used splitting mode
        DBL   :176C     Start graph temp save area
*
        DBL   :00A0     Number of blobs horizontally
        DATA  :82       Number of lines of graphics
        DATA  :18       Number saved graphics lines
        DATA  :2E       Number of bytes/line
*
****************************
* CONSTANT TABLE MODES 5/6 *
****************************
*
CON5    DBL   :5A20     First free RAM byte
        DBL   :0F88     Top area rolled up
        DBL   :5A10     End graphics area
        DBL   :5A10     CHS (dummy)
        DBL   :5C48     End character area
        DBL   :5A20     End screen
        DBL   :6988     End area used splitting mode
        DBL   :4CD0     Start graph archive area
*
        DBL   :0150     Number of blobs horizontally
        DATA  :00       Number of lines of graphics
        DATA  :2C       Number saved graphics lines
        DATA  :5A       Number of bytes/line
*
******************************
* CONSTANT TABLE MODES 5A/6A *
******************************
*
CON5A   DBL   :5C48     First free RAM byte
        DBL   :0F88     Top of rolled area
        DBL   :4A98     End graphics area
        DBL   :4AA8     Start character area
        DBL   :4CC0     End character area
        DBL   :4CD0     End screen
        DBL   :6988     End area used splitting mode
        DBL   :5A10     Start graph temp save area
*
        DBL   :0150     Number of blobs horizontally
        DATA  :00       Number of lines of graphics
        DATA  :2C       Number saved graphics lines
        DATA  :5A       Number of bytes/line
*
*********************
* INITIALISE SCREEN *
*********************
*
* The screen is initialised into all character
* format (mode 0), and the cursor mode is set
* and it is positioned in the top left corner.
* The normal mode set routine is used (memory
* management routine).
*
* This is the only time the package is told the
* startaddress of the screen. The colour format
* is as for SCOLT, SCOLG. The cursor format is
* as for SCURM.
*
* Entry: HL: Top location screen RAM.
*        DE: Points to list with initialisation
*            parameters (start at C7E0).
* Exit:  All registers maybe corrupted.
*
SINIT   SHLD  SCREEN    Store startaddr screen
        PUSH  D
        LXI   D,:FFF0
        DAD   D
        SHLD  SCTOP     Set top of screen
        POP   H
        XRA   A
        STA   COL1      Select mode 1
        CALL  SCURM     Set cursor type + info
        INX   H
        INX   H
        CALL  SCOLT     Init. colours COLORT
        DCR   A
        STA   COL1      Select mode 0
        LXI   D,:0004
        DAD   D         Get addr COLORG parameters
        CALL  SCOLG     Init. colours COLORG
        DAD   D         Get addr screen management
 REM parameters
        MOV   E,M       )
        INX   H         ) Get addr screen management
        MOV   D,M       ) routine
        INX   H
        XCHG
        SHLD  ASMKRM    Store addr SMKRM
        XCHG
        MOV   E,M       ) Get addr emergency
        INX   H         ) stop routine
        MOV   D,M       )
        XCHG
        SHLD  AESTOP    Store addr em.stop routine
        MVI   A,:10
        STA   COL1      Select init. screen mode
 REM (no text, no graphics)
        MVI   A,:FF
        CALL  SSETM     Set up screen for mode 0
        RET 
*
********************************
* OUTPUT A CHARACTER TO SCREEN *
********************************
*
* Displays one character on the screen.
*
* Entry: A: Character to be displayed.
* Exit:  ABCDEHL preserved.
*        CY=1: Character ignored.
*
SOUTC   STC             CY=1
        PUSH  PSW
        PUSH  B
        PUSH  D
        PUSH  H
        CALL  TMODE     Change to char mode if
 REM not yet done
        LHLD  CURSOR    Get cursor position
        CALL  CURDEL    Delete cursor
        CPI   :0D       Car.ret ?
        JZ    OTC30     Then print it
        CPI   :0C       Form feed ?
        JZ    OTC40     Then clear screen
        CPI   :08       Backspace ?
        JZ    OTC50     Then cancell last character
        PUSH  PSW
        LDA   LINLEN    Get addr last byte on line
        CMP   L         Reached ?
        JZ    OTC80     Then extend lines
OTC05   POP   PSW
        MOV   M,A       Put char on screen
        DCX   H
        DCX   H         Points to next screen loc
OTC10   CALL  CURSET    Put cursor on screen
*
*OTC20
XRCC    POP   H
        POP   D
        POP   B
        POP   PSW
        CMC             CY=0: char accepted
        RET 
 REM
* If character not accepted:
 REM
OTC25   POP   PSW
OTC26   CALL  CURSET    Put cursor on screen
XRET    POP   H
        POP   D
        POP   B
        POP   PSW       CY=1: char ignored
        RET 
 REM
* If carriage return:
 REM
OTC30   LHLD  LNSTR     Get startaddr current line
        XCHG            in DE
        LXI   H,:FF7A
        DAD   D         Get startaddr next line
        XCHG            in DE
        LHLD  GAE       Get end char area
        CALL  COMP      Check if end is reached
        XCHG            Next line mode byte in HL
        CZ    SCROLL    If end reached: scroll up
 REM one line
        CZ    FILLS     and init. this line with
 REM blanks
OTC35   CALL  SSETC     Cursor on begin next line
        JMP   OTC20     Quit; char accepted
 REM
* If form feed:
 REM
OTC40   LHLD  GAE       Get end character area
        XCHG            in DE
        LHLD  CHS       Get start character area
        CALL  FILLS     Init screen with spaces
        JMP   OTC35     Cursor top left corner of
 REM char area; popall; ret
 REM
* If backspace:
 REM
OTC50   XCHG            Cursor position in DE
        LHLD  LNSTR     Get startaddr current line
        LXI   B,TICC8   Left border width
        DAD   B         Get addr 1st char on line
        CALL  COMP      Cursor at begin of line?
        XCHG
        JZ    OTC26     Then ignore char; abort
        INX   H         ) Cursor one location
        INX   H         ) backwards
        MVI   M,:20     Load space in this location
        LDA   ERRCOD    Get number of extended lines
        ORA   A
        JZ    OTC10     If no cont line: put cursor
 REM on screen
        JM    OTC10     If char accepted: put
 REM cursor on screen
 REM
* Backspace on a continuation line:
 REM
        PUSH  D         Save addr 1st byte on line
 REM on stack
        XCHG            HL is cursor position
        LXI   B,TICCST
        DAD   B         HL = end indent area
        CALL  COMP      Compare DE-HL
        XCHG
        POP   D
        JNZ   OTC10     If not there: put cursor on
 REM screen; quit, char accepted
        XCHG
        MVI   M,:20     Else cancel cont char (C)
        LXI   H,ERRCOD
        DCR   M         Decr. number extended lines
        LHLD  LNSTR     Get startaddr current line
        LXI   D,:0086
        DAD   D         Pnts to start previous line
        CALL  SSETL     Store addr line mode byte as
 REM current one and set last
 REM byte on that line
        LXI   D,:FF80
        DAD   D
        JMP   OTC10     Put cursor on screen; quit,
 REM char accepted
 REM
* If end of line is reached:
 REM
OTC80   LDA   ERRCOD    Get number extended lines
        CPI   :03       Max (3) reached ?
        JNC   OTC25     Then put cursor on screen,
 REM ret
        INR   A         Incr. number ext. lines
        MOV   B,A       Store it in B
        MVI   A,:0D
        CALL  SOUTC     Output car.ret
        MOV   A,B
        STA   ERRCOD    Update nr ext. lines
        LHLD  CURSOR    Get cursor position addr
        CALL  CURDEL    Delete cursor
        MVI   M,:43     Print 'C' at left of line
        LXI   D,:FFF2
        DAD   D         Indent 6 pos
        JMP   OTC05     Store char on new pos; put
 REM cursor on screen
*
*************
* SCROLLING *
*************
*
* Scrolls up text area. Moves the character area of
* the screen up one line.
* Only the characters are moved, not the control and
* colour bytes.
*
* Entry: None.
* Exit:  AF preserved, BC corrupted.
*        DE: End of bottom line.
*        HL: Start of bottom line.
*
SCROLL  LXI   B,:FF7A   -86 (length one line)
 REM
* Entry from Edit:
* Scroll screen for number of positions given in
* BC (-2 = 1 position left):
 REM
SCR10   PUSH  PSW
        LHLD  CHS       Get startaddr character area
        MOV   D,H       ) and store it in DE
        MOV   E,L       )
        DAD   B         Get addr line mode byte
 REM next line
        XCHG            in DE
SCR20   LXI   B,TICC8
        DAD   B         Get 1st useable location
 REM on 1st line
        XCHG            in DE
        DAD   B         Get 1st useable location
 REM on 2nd line
        XCHG            in DE; 1st line in HL
        MVI   B,:3C     max 60 characters
SCR30   LDAX  D         Get char from 2nd line
        MOV   M,A       and move it to 1st line
        DCX   D
        DCX   D         Next char 2nd line
        DCX   H
        DCX   H         Next loc 1st line
        DCR   B
        JNZ   SCR30     Next char to be moved 1 line
        LXI   B,:FFFA
        DAD   B         Get addr line mode byte
 REM 2nd line
        XCHG            in DE
        DAD   B         Get addr line mode byte
 REM 3rd line
        XCHG            in DE; 2nd line in HL
        PUSH  H
        LHLD  GAE       Get addr end character area
        CALL  COMP      Check if end reached
        POP   H
        JC    SCR20     If not at end: scroll next
 REM line
        POP   PSW
        RET 
*
*
*
        UNL
SCOLT   EQU   :E237
SCURS   EQU   :E279
SCURA   EQU   :E2CC
SCURM   EQU   :E316
SCURI   EQU   :E344
SFETC   EQU   :E38B
SSETM   EQU   :E3D9
SCOLG   EQU   :E6A4
SDOT    EQU   :E710
SDRAW   EQU   :E71B
SFILL   EQU   :E818
SSCRN   EQU   :E884
EINIT   EQU   :EBF4
EOBEY   EQU   :EC1E
SCREEN  EQU   :0080
SCTOP   EQU   :0082
COL1    EQU   :009D
ASMKRM  EQU   :00C4
AESTOP  EQU   :00C6
TMODE   EQU   :E21C
CURSOR  EQU   :0072
CURDEL  EQU   :E36B
LINLEN  EQU   :007A
CURSET  EQU   :E330
LNSTR   EQU   :0078
GAE     EQU   :008C
COMP    EQU   :E6FB
FILLS   EQU   :E1FD
SSETC   EQU   :E687
OTC20   EQU   :E12E
CHS     EQU   :008A
TICC8   EQU   :FFF8
ERRCOD  EQU   :007B
TICCST  EQU   :FFF2
SSETL   EQU   :E698
        LST
        END 
